<template>
	<div class="view">
		<el-row :gutter="10">
			<el-col :span="5">
				<el-input v-model="search.name" placeholder="查询"></el-input>
			</el-col>
			<el-col :span="19">
				<el-button type="primary" icon="el-icon-search" plain @click="searchData()">搜索</el-button>
				<el-button type="primary" icion="el-icon-circle-plus-outline" plain @click="add()">添加</el-button>
			</el-col>
		</el-row>
		<el-table :data="result.tableData" class="eltable" style="width: 99%;font-size: 12px;
		box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)"
		 @selection-change="handleSelectionChange">


			<el-table-column width="120" label="序号" prop="nid"></el-table-column>
			<el-table-column width="120" label="编号" prop="number"></el-table-column>
			<el-table-column width="120" label="名称" prop="name"></el-table-column>
			<el-table-column width="110" label="价格" prop="price"></el-table-column>
			<el-table-column width="120" label="是否增值服务" prop="serve"></el-table-column>
			<el-table-column width="100" label="状态" prop="status"></el-table-column>
			<el-table-column width="120" label="护理级别" prop="level"></el-table-column>
			<el-table-column width="100" label="备注" prop="note"></el-table-column>

			<el-table-column label="操作" width="220px">
				<template slot-scope="scope">
					<template>
						<el-button size="mini" @click="handleEdit(scope.row.nid)">编辑</el-button>
						<el-button size="mini" type="danger" @click="handleDelete(scope.row.nid)">删除</el-button>
					</template>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination style="margin-top:10px;" background layout="prev, pager, next" :page-count="result.pages"
		 :current-page.sync="query.current" :page-size="query.size" @current-change="getData()">
		</el-pagination>
		<el-dialog :title="title" :visible.sync="show" :close-on-click-modal="false" width="500px">
			<nContentEdit v-if="show" :show.sync="show" @getData="getData()" :editid="editid"></nContentEdit>
		</el-dialog>
	</div>
</template>

<script>
	import nContentEdit from '@/views/n_content/edit.vue'
	export default {
		name: 'nContent',

		data() {
			return {
				search: {
					name: ''
				},
				query: {
					name: '',
					current: 1,
					size: 8
				},
				result: {
					tableData: [],
					pages: 0
				},
				show: false,
				editid: null,
				selectedrow: [],
				title: ''
			}
		},
		components: {
			nContentEdit
		},
		created() {
			this.getData()
		},
		methods: {
			getData() {
				this.axios.get('/nContent/list', response => {
					// console.log(this.query.pageNo)
					this.result.tableData = response.obj.records
					// console.log(response.obj.total)
					// this.query.pageNo=response.obj.current
					this.result.pages = response.obj.pages

				}, this.query)
			},
			searchData() {
				// console.log(this.search)
				this.query.name = this.search.name
				console.log(this.query.name)
				this.query.current = 1
				this.getData()
			},
			handleEdit(id) {
				this.title = '修改名称'
				this.editid = id
				this.show = true
			},
			add() {
				this.title = '添加名称'
				this.editid = null
				this.show = true
			},
			handleDelete(id) {
				console.log(id);
				this.axios.del('/nContent/delete/' + id, response => {
					this.getData()
				}, {
					nId: id
				})
			},
			handleSelectionChange(val) {
				// val参数为所有选中行的数据
				this.selectedrow = val
			},
		}
	}
</script>
<style scoped>
	.view {
		font-size: 12px;
	}

	.eltable {
		width: 20px;
		padding: 0px;
	}

	.el-table-column {}
</style>
